package Q1;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Arrays;

public class saveloadTest {
    public static void main(String[] args) {
        Student s1 = null;
        Student s2 = null;
        Student s3 = null;
        try {
            s1 = new Student(1, "张三", 17);
            s2 = new Student(2, "李四", 17);
            s3 = new Student(3, "王五", 18);
        } catch (IDException | AgeException e) {
            e.printStackTrace();
        }
        ArrayList<Student> DefaultSys = new ArrayList<>(Arrays.asList(s1,s2,s3));
        StudentData studentData = new StudentData(DefaultSys);
        studentData.save();

        ObjectInputStream stream = null;
        Object data = null;
        try {
            stream = new ObjectInputStream(new FileInputStream("StudentData.save"));
            data = stream.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                if (stream != null) {
                    stream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        System.out.println(DefaultSys.equals(data));
        System.out.println((ArrayList<Student>) data);

    }
}
